/**
 * Created with Vim7.3 Mac
 * @fileOverview : 
 * @author : Lyle lylechen2014@gmail.com
 * @since : 2016-09-29 15:32:18
 * @filename : src/components/sliderCards.js
 * @version : 
 * @description : 
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity
} from 'react-native';


import Card from './card'

let { width, height } = Utils.size;

class SliderCards extends Component {

    constructor(props) {
        super(props);
        this.state = {
            cards: this.props.cardList,
        };
    }

    createCards() {
        let items=[],cardList = this.state.cards;
        if (cardList && cardList.length > 0) {
            for (let i = cardList.length-1; i >= 0; i--) {
                let key = cardList[i].picture;
                //let key = i+cardList[i].picture;
                    items.push(
                        <Card index = {i} removeCards={this.removeCards.bind(this)}  card={cardList[i]} key={key}/> 
                    )
            }
        }
        return items;
    }

    render() {
        return (
            <View style={styles.container}>  
                {this.createCards()}
            </View>
        )
    }

    removeCards() {
        let arr = this.state.cards;
        arr.shift();
        this.setState({cards:arr});
    }

}

const styles = StyleSheet.create({
    
    container: {
        flex: 1,
    }

});

export default SliderCards;